home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
network
/
midi
/
midinet.arc
/
ANETMIDI.MOD
< prev
next >
Wrap
Text File
|
1987-03-08
|
32KB
|
905 lines
MODULE NETWORK ; (* by fred brooks PD software *)
(* --------------------------------------------------------------------------
NETWORK : MIDI MULTI CPU NETWORK FOR TDI Modula-2/ST
--------------------------------------------------------------------------*)
(*$T- *) (*$S- *)
FROM SYSTEM IMPORT ADDRESS, ADR, SETREG, CODE, REGISTER ,BYTE ,TSIZE,SIZE;
FROM GEMX IMPORT BasePageAddress, BasePageType ;
FROM BIOS IMPORT BPB ,BConStat ,BConIn, BCosStat, BConOut, Device,
MediaChange,MCState,GetBPB,RWAbs,RW,DriveSet,DriveMap;
FROM XBIOS IMPORT SuperExec,SerialDevice,IORec,IORECPTR,IOREC,VSync;
FROM GEMDOS IMPORT TermRes,Open,Close ;
IMPORT GEMDOS;
FROM ASCII IMPORT SYN,STX,SOH,BEL;
CONST
MaxSeq = 1;
recsize = 511;
MAGIC = 3141592653;
USERS = 16;
retry = 10;
debug = FALSE;
trace = FALSE;
(* Because we dont know what registers the BIOS is using we must use
the following opcodes to save the registers *)
MOVEMDEC = 48E7H ; (* 68000 opcode for MOVEM <regs>,-(A7) *)
MOVEMINC = 4CDFH ; (* 68000 opcode for MOVEM (A7)+,<regs> *)
SAVEREGS = 07FFCH ; (* Registers D1..A5 for DEC *)
RESTREGS = 03FFEH ; (* Registers D1..A5 for INC *)
RTS = 04E75H ; (* 68000 return from subroutine opcode *)
TYPE
(* Procedure types to mimic correct sequence for "C" BIOS routines *)
CBPBProc = PROCEDURE ( CARDINAL ) ;
CMediaChProc = PROCEDURE ( CARDINAL ) ;
CRWAbsProc = PROCEDURE ( CARDINAL, CARDINAL, CARDINAL, ADDRESS, CARDINAL );
midibuffer = ARRAY [0..2000] OF CARDINAL;
SequenceNr = [0..MaxSeq];
message = ARRAY [0..recsize] OF BYTE;
message1 = ARRAY [0..17] OF BYTE;
FrameKind = (ack,data,resetreq,resetconf,diag);
DataKind = (rdmediareq,rdmediaconf,rdbpbreq,rdbpbconf,
rdrwabsreq,rdrwabsconf);
evtype = (framearrival,cksumerr,timeout,hostready,reset,nothing);
frame = RECORD
syn : CHAR; (* these are sync chars *)
stx : CHAR; (* for the frames *)
kind : FrameKind;
seq : SequenceNr;
ack : SequenceNr;
cmd : DataKind;
rw : CARDINAL; (* read or write data *)
recno : CARDINAL; (* sector for data*)
d0 : LONGCARD; (* data return variable *)
info : message;
user : CARDINAL;
remoteuser : CARDINAL;
cksum : CARDINAL;
END;
framecptr = POINTER TO framecmd;
framecmd = RECORD
syn : CHAR; (* these are sync chars *)
stx : CHAR; (* for the frames *)
kind : FrameKind;
seq : SequenceNr;
ack : SequenceNr;
cmd : DataKind;
rw : CARDINAL; (* read or write data *)
recno : CARDINAL; (* sector for data*)
d0 : LONGCARD; (* data return variable *)
info : message1;
user : CARDINAL;
remoteuser : CARDINAL;
cksum : CARDINAL;
END;
control = RECORD
magic : LONGCARD;
USER : CARDINAL;
REMOTEUSER : CARDINAL;
reset : BOOLEAN;
networkactive : BOOLEAN;
remotedrive : CARDINAL;
drivemap : DriveSet;
nextframetosend : ARRAY [0..15] OF SequenceNr;
frameexpected : ARRAY [0..15] OF SequenceNr;
sendreset : BOOLEAN;
END;
consave = RECORD
magic : LONGCARD;
USER : CARDINAL;
REMOTEUSER : CARDINAL;
reset : BOOLEAN;
networkactive : BOOLEAN;
END;
vblqueueptr = POINTER TO ADDRESS;
frameptr = POINTER TO ARRAY [0..1024] OF BYTE;
VAR
(* BIOS variables : These can only be accessed with the 68000 in supervisor
mode. The Modula-2 language allows you to fix the location of variables *)
HDBPB [0472H] : ADDRESS ; (* hard disk get Bios Parameter Block *)
HDRWAbs [0476H] : ADDRESS ; (* hard disk read/write abs *)
HDMediaCh [047EH] : ADDRESS ; (* hard disk media change *)
DriveBits [04C2H] : SET OF [0..31]; (* disk drives present map *)
Cptr [0210H] : ADDRESS; (* control record pointer *)
Dptr [0214H] : DriveSet; (* save original drive map *)
Mptr [0218H] : LONGCARD;
charcount,framesize,cksum,recframesize,sndframesize,
SIZEframe,SIZEframecmd : CARDINAL;
vblqueue : vblqueueptr; (* set to vbl routines vector *)
vblptr : vblqueueptr;
networkconnect : BOOLEAN; (* DCD = 1 TRUE *)
gotframe : BOOLEAN;
framebufferfull : BOOLEAN;
cleartosend : BOOLEAN;
readytosend : BOOLEAN;
requesttosend : BOOLEAN;
framewaiting : BOOLEAN;
timer,OK : BOOLEAN;
gotmediach : ARRAY [0..5] OF BOOLEAN;
gotbpb : ARRAY [0..5] OF BOOLEAN;
vblactive : BOOLEAN;
networkerror : BOOLEAN;
shortframe : BOOLEAN;
sframe,rframe,SFRAME,RFRAME,
nframe1,nframe2 : frame;
rframeptr,sframeptr,
bpbptr,nbpbptr : frameptr;
framecmdptr,framecmdptr1 : framecptr;
event : evtype;
C : control;
recchar,timestart,timefortimeout,timeouttime : LONGCARD;
timestart1,timefortimeout1,timeouttime1 : LONGCARD;
i,i1,i2,i3,mediacount,handle : INTEGER;
wsector,drvnr,DriveA,DriveF,devicestart,d,R,
REMOTEUSER,receivedfromuser : CARDINAL;
rbuffer : midibuffer;
rbptr : IORECPTR;
numBytes,sec,min,hour,time,count : LONGCARD ;
status : LONGINT ;
(* The following are saved copies of the BIOS variables so that the real
hard disk routines can be called if a hard disk access is requested. *)
SaveHDBPB : CBPBProc ; (* hard disk get Bios Parameter Block *)
SaveHDRWAbs : CRWAbsProc ; (* hard disk read/write abs *)
SaveHDMediaCh : CMediaChProc ; (* hard disk media change *)
(* NETWORK control *)
NetworkBPB : ARRAY [0..5] OF BPB ; (* BIOS Parameter block for NETWORK *)
PROCEDURE MoveMemory ( From, To : ADDRESS ; Bytes : LONGCARD ) ;
(* This routine shows how time critical portions of code can be optimised to
run faster. It relys on the code generation rules of the compiler which
can be checked by dis-assembling the link file with DecLnk.*)
CONST
MOVEB = 12D8H ; (* MOVE.B (A0)+,(A1)+ *)
MOVEL = 22D8H ; (* MOVE.L (A0)+,(A1)+ *)
A0 = 0+8 ; (* register A0 *)
A1 = 1+8 ; (* register A1 *)
BEGIN
SETREG(A0,From) ; (* load From pointer into A0 *)
SETREG(A1,To) ; (* load To pointer into A1 *)
IF ( ODD(From) OR ODD(To) ) THEN (* must do bytes *)
WHILE ( Bytes <> 0 ) DO
CODE(MOVEB) ;
DEC(Bytes) ;
END ;
ELSE (* even addresses so can do long moves *)
WHILE ( Bytes > 3 ) DO
CO